using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Collections;

namespace XPad
{
    class Config
    {
        static string KeyName = "Software\\XPad";

        public static object GetProp(string PropName, object DefaultValue)
        {
            RegistryKey key = Registry.CurrentUser.OpenSubKey(KeyName);
            if (key == null)
            {
                key = Registry.CurrentUser.CreateSubKey(KeyName);
                key.SetValue(PropName, DefaultValue);
            }
            object value = key.GetValue(PropName, DefaultValue);
            return value;
        }

        public static void SetProp(string PropName, object Value)
        {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(KeyName);
            key.SetValue(PropName, Value);
        }

        public static ArrayList GetRecentFiles()
        {
            ArrayList files = new ArrayList();
            RegistryKey key = Registry.CurrentUser.CreateSubKey(KeyName).CreateSubKey("Recent");
            string[] names = key.GetValueNames();
            for (int i = 0; i < names.Length; i++)
                files.Add(key.GetValue(names[i]));
            return files;
        }

        public static void SetRecentFiles(ArrayList files)
        {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(KeyName).CreateSubKey("Recent");

            string[] names = key.GetValueNames();
            for(int i = 0; i < names.Length; i++) key.DeleteValue(names[i]);

            for (int i = 0; i < files.Count; i++)
                key.SetValue("file" + i.ToString(), files[i]);
        }
    }
}
